package com.xca.znb.presenter;

import com.xca.znb.R;
import com.xca.znb.contact.PersonalCenterContact;
import com.xca.znb.entity.User;
import com.xca.znb.model.imodel.IPersonalCenter;

public class PersonalCenterPresenter {
    private PersonalCenterContact personalCenterContact ;
    private IPersonalCenter iPersonalCenter ;
    public PersonalCenterPresenter(PersonalCenterContact contact , IPersonalCenter personalCenter){
        this.personalCenterContact = contact ;
        this.iPersonalCenter = personalCenter ;
    }

    //将用户信息展示到页面上
    public void showMessage(String phone){
        User user = iPersonalCenter.getUser(phone);
        if (user != null){
            String avatarPath = user.getConcern();
            String name = user.getName();
            String age = user.getAge();
            String local = user.getLocal();

            if (avatarPath == null){
                personalCenterContact.updateAvatar(String.valueOf(R.drawable.mine_a));
            }else {
                personalCenterContact.updateAvatar(avatarPath);
            }
            personalCenterContact.updateAvatar(avatarPath);
            if (name == null ){
                personalCenterContact.updateName("未设置");
            }else {
                personalCenterContact.updateName(name);
            }
            if (age == null ){
                personalCenterContact.updateAge("未设置");
            }else {
                personalCenterContact.updateAge(age);
            }
            if (local == null ){
                personalCenterContact.updateLocal("未设置");
            }else {
                personalCenterContact.updateLocal(local);
            }
        }
    }
    public void updateAvatar(String phone , String avatarPath){
        iPersonalCenter.updateConcern(phone,avatarPath);
    }
    public void updateName(String phone , String newName){
        iPersonalCenter.updateName(phone, newName);
    }
    public void updateAge(String phone , String newAge){
        iPersonalCenter.updateAge(phone, newAge);
    }
    public void updateLocal(String phone , String newLocal){
        iPersonalCenter.updateLocal(phone, newLocal);
    }
}
